<template>
    <div class="goods-list">
         <router-link class="goods-item" v-for="item in list" :key="item.id" :to="'/goodslist/goodsinfo/' + item.id" tag="div">
            <img :src="item.img_url" alt="图片加载不出来!">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
                </p>
            </div>
        </router-link>
        <van-button type="danger" size="large" @click="GetMore">加载更多</van-button>
    </div>
</template>

<script>
export default {
    data(){
        return{
            pageindex: '1',
            list:[]
        }
    },
    created() {
        this.GetGoodsList()
    },
    methods: {
        GetGoodsList(){
            this.$ajax
            .request({url:"http://www.liulongbin.top:3005/api/getgoods?pageindex=" + this.pageindex,method:"Get"})
            .then(ret =>{
                if(ret.data.status === 0){
                    this.list = this.list.concat(ret.data.message);
                   if(this.list.length === this.list.concat(ret.data.message).length)
                    Toast({
                        message: "已经是最后一页了!",
                        position: "middle",
                        duration: 1000
                    })
                }
            })
        },
        GetMore(){
            this.pageindex++;
            this.GetGoodsList();
        }
    },
}
</script>

<style scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 7px;
    justify-content: space-between;
    margin-bottom: 40px;
    margin: 46px 0 50px 0;
}
.goods-item{
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 3px 5px #ccc;
    margin:3px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 250px;
}
img{
    width: 100%;
}
.title{
    font-size: 14px;
}
.info{
    background-color: #ccc;
}
.info p{
    margin: 0;
    padding: 2px;
}
.price .now{
    color: red;
    font-weight: bold;
    font-size: 16px;
}
.price .old{
    text-decoration: line-through;
    font-size: 12px;
    margin-left: 10px;
}
.sell{
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}
</style>